package model.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import model.bean.Configuracao;
import model.interfaces.IConfiguracao;

public class ConfiguracaoDAO implements IConfiguracao {
	public EntityManager getEntitymanager(){
		EntityManagerFactory factory = null;
		EntityManager manager = null;
		
		try{
			factory = Persistence.createEntityManagerFactory("SmartClassroomPUnit");
			manager = factory.createEntityManager();
		}catch(Exception e){
			System.out.println("Erro : " + e);
		}finally{
			factory.close();
		}
		
		return manager;
	}

	@Override
	public void cadastraConfiguracao(Configuracao configuracao) {
		EntityManager manager = getEntitymanager();
		try{
			manager.getTransaction().begin();
			System.out.println("Cadastrando Configuracao " + configuracao.getDescricao());
			manager.persist(configuracao);
			manager.getTransaction().commit();
		}catch(Exception e){
			System.out.println("Erro : " + e);
		}finally{
			manager.close();
			System.out.println("Participante Inserido com sucesso...");
		}
		
	}

	@Override
	public String getDescricaoConfiguracao(Configuracao configuracao) {
		return configuracao.getDescricao();
	}
	
	
	
}
